**********************
* Main Table 2
**********************
* loading pixel data
import delimited "vcf_data_complete.csv", delimiter(",") clear

keep if year>=1995
keep if year<=2017

gen t = year-1995


local packs reghdfe estout
foreach pack of local packs{
	
	display( "`pack'" )
	capture which `pack'
	if _rc == 111{
		net install `pack', replace
	}

	if _rc != 111{
		display( "`pack' installed" )
	}
}




* running regressions - appendix
est clear
scalar drop _all 
foreach sector in mining {		
eststo: reghdfe con_`sector'50  c.sch#c.d, absorb(cellid styear i.cellid#c.t) cluster(blk)
	sum con_`sector'50 if sch == 0
	estadd scalar nschmean = `r(mean)'
	sum con_`sector'50 if sch == 1
	estadd scalar schmean = `r(mean)'


	preserve 
		keep cellid
		duplicates drop
		count

		local aux `r(N)'
	restore
	estadd local fe_cellid `aux'


	local aux "VCF"
	estadd local dataset `aux'
	local aux "1995-2017"
	estadd local timespan `aux'
	estadd local fe `'
	local aux "$\\checkmark$"
	estadd local pixel `aux'
	estadd local styear `aux'
	estadd local timetrend `'
	estadd local tpix `aux'
	local aux "198"
	estadd local styear2 `aux'

eststo: reghdfe con_`sector'50  c.sch#c.d if forest_cover==1, absorb(cellid styear i.cellid#c.t) cluster(blk)
	sum con_`sector'50 if sch == 0 & forest_cover==1
	est1add scalar nschmean = `r(mean)'
	sum con_`sector'50 if sch == 1 & forest_cover==1
	estadd scalar schmean = `r(mean)'

	preserve 
		keep if forest_cover==1
		keep cellid
		duplicates drop
		count

		local aux `r(N)'
	restore
	estadd local fe_cellid `aux'	


	local aux "VCF"
	estadd local dataset `aux'
	local aux "1995-2017"
	estadd local timespan `aux'
	estadd local fe `'
	local aux "$\\checkmark$"
	estadd local pixel `aux'
	estadd local styear `aux'
	estadd local timetrend `'
	estadd local tpix `aux'
	local aux "198"
	estadd local styear2 `aux'
}


esttab est1 est2 using "main_table2.tex", ///
replace cells(b (fmt(%9.4f)) se(par fmt(%9.4f))) style(tex) ///
stats(nschmean schmean dataset timespan ///
	fe pixel styear ///
	timetrend tpix ///
	fit_stat fe_cellid styear2 N r2, layout(@ @ @ @ @ @ @ @ @ @ @ @ @ @) ///
label("\midrule Mean Pre-Y (Non-Sch)" "Mean Pre-Y (Sched)" "Dataset" "Timespan" ///
	"\midrule \emph{Fixed-effects}" "Pixel" "State $\times$ Year" ///
	"\midrule \emph{Time Trends}" "t (Pixel)" ///
	"\midrule \emph{Fit statistics}" "\# Pixel" "\# State $\times$ Year" "\# Observations" "R^2"  ) ///
fmt(%9.4f %9.4f %9.0f %9.4f %9.4f %9.4f %9.4f %9.4f %9.4f %9.4f %9.0f %9.0f %9.0f %9.3f)) ///
starlevels(* .1 ** .05 *** .01) ///
keep(c.sch#c.d) order() ///
varlabels(c.sch#c.d "PESA X Scheduled") ///
collabels(none) ///
delim("&")  ///
noobs ///
nomtitle ///
label ///
width(1.5\hsize) ///
nogaps /// No gaps between rows
booktabs /// Style
nonote /// No notes
prehead( "\begin{table} \small \centering \protect \captionsetup{justification=centering} \caption{\label{tab:table5} The Impact of Increased Representation on Onset of Mining Conflict }" "\noindent \scalebox{1}{ \begin{threeparttable}" "\begin{tabular}{lcc}" \toprule ) ///
posthead(\hline) prefoot("")  ///
postfoot(\hline \hline \end{tabular} ///
\begin{tablenotes} ///
\begin{footnotesize} ///
"\par \raggedright \emph{Notes:} Standard errors are clustered at the block level and reported in parentheses. Conflict data isfrom Land Conflict Watch (2022)." ///
\end{footnotesize} ///
"\end{tablenotes} \end{threeparttable} } \end{table}")

		
